package com.meusdrinks.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.inject.Inject;
import javax.inject.Named;

import com.meusdrinks.business.IngredienteBC;
import com.meusdrinks.domain.Ingrediente;

@Named(value="ingredienteConverter")
public class IngredienteConverter implements Converter {
	
	@Inject
	private IngredienteBC ingredienteBC;

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
		Ingrediente i = ingredienteBC.load(Long.parseLong(value));
		return i;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object obj) {
		Ingrediente i = (Ingrediente) obj;
		return String.valueOf(i.getId());
	}

}
